package com.springark.ms.springarkgateway.config;

import com.springark.ms.springarkgateway.limiter.AppIdKeyResolver;
import org.springframework.cloud.gateway.filter.factory.RequestRateLimiterGatewayFilterFactory;
import org.springframework.cloud.gateway.filter.ratelimit.RedisRateLimiter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @author hankchan
 * @since 2019/5/11
 */
@Configuration
public class GatewayFilterConfiguration {

//    @Primary
//    @Bean
//    public RequestRateLimiterGatewayFilterFactory requestRateLimiterGatewayFilterFactory() {
//        return new RequestRateLimiterGatewayFilterFactory(
//                new RedisRateLimiter(1, 2), new AppIdKeyResolver());
//    }

//    @Primary
//    @Bean(name = PrincipalNameKeyResolver.BEAN_NAME)
//    @ConditionalOnBean(RateLimiter.class)
//    public KeyResolver appIdKeyResolver() {
//        return new AppIdKeyResolver();
//    }

//    @Bean("redisRateLimiter")
//    public RedisRateLimiter redisRateLimiter() {
//        return new RedisRateLimiter(1, 2);
//    }
}
